using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarineReducePowerOnShockComponent
/// \brief  Nullify the power when the submarine get shocked
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarineReducePowerOnShockComponent")]
public class gkAbyssalGiantSubmarineReducePowerOnShockComponent : MonoBehaviour
{
	/// The power component
	private gkPowerComponent m_rPowerComponent;

	/// \brief  Called just after the game begin to play
	void Start()
	{
		// Grab the power component
		m_rPowerComponent = GetComponent<gkPowerComponent>();
	}
	
	/// \brief Called when the component is enabled
	void OnEnable() 
	{
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// \brief Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}

	/// Handle the begin shock event
	void HandleShockBeginEvent(Object a_rEvent)
	{
		m_rPowerComponent.Reset();
	}
}
